package demo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TranslationApp extends JFrame {

    private JTextField wordTextField;
    private JButton searchButton;
    private JButton searchAllButton;
    private JButton addButton;
    private JButton editButton;
    private JButton deleteButton;
    private JTextArea displayArea;

    public TranslationApp() {
        setTitle("英语释义查询");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        wordTextField = new JTextField(20);
        searchButton = new JButton("查询");
        searchAllButton = new JButton("查询所有");
        addButton = new JButton("添加词典");
        editButton = new JButton("修改词典");
        deleteButton = new JButton("删除词典");
        displayArea = new JTextArea(10, 30);

        JPanel inputPanel = new JPanel();
        inputPanel.add(new JLabel("输入你要查询的单词："));
        inputPanel.add(wordTextField);
        inputPanel.add(searchButton);
        inputPanel.add(searchAllButton);
        inputPanel.add(addButton);
        inputPanel.add(editButton);
        inputPanel.add(deleteButton);

        add(inputPanel, BorderLayout.NORTH);
        add(new JScrollPane(displayArea), BorderLayout.CENTER);

        searchButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String word = wordTextField.getText();
                // Perform search for the word
                displayArea.setText("Search result for " + word + ":\n");
                // Display the search result in the display area
            }
        });

        searchAllButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Perform search for all words
                displayArea.setText("All words in the dictionary:\n");
                // Display all words in the display area
            }
        });

        addButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Open a dialog to add a new word to the dictionary
            }
        });

        editButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Open a dialog to edit an existing word in the dictionary
            }
        });

        deleteButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Open a dialog to delete a word from the dictionary
            }
        });

        // Center the frame on the screen
        setLocationRelativeTo(null);
        // Allow the frame to be resizable
        setResizable(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new TranslationApp().setVisible(true);
            }
        });
    }
}
